package com.edu.controller;

import com.edu.bean.Admin;
import com.edu.service.AdminService;
import com.edu.service.impl.AdminServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;

/**
 * @Author:xgdxqr
 * @Date:2025/9/19-13:23-10
 **/
@WebServlet("/login.do")
public class LoginServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        AdminService adminService = new AdminServiceImpl();
        String account = req.getParameter("account");
        String password = req.getParameter("password");
        Map<String ,Object> adminMap = adminService.login(account,password);
        if(adminMap.get("admin")!=null){
            resp.sendRedirect("getGoods.do");
        }else{
            req.setAttribute("errorLogin", adminMap.get("errorLogin"));
            resp.sendRedirect("index.jsp");
        }
    }
}
